package com.zwy.leetCode;

import java.util.LinkedList;
import java.util.List;

public class Day10Test {
    /**
     * 152. 乘积最大子数组
     * @param nums
     * @return
     */

    public int maxProduct(int[] nums) {
        if(nums.length==1)return nums[0];
        int max=0;
        int []dp=new int[nums.length];
        dp[0]=nums[0];
        for (int i = 1; i < dp.length; i++) {
            if(Math.abs(nums[i-1])>=1)
            dp[i]=Math.max(dp[i-1]*nums[i],nums[i]);
            else
                dp[i]=nums[i];
            if(dp[i]>0)
            max=Math.max(max,Math.abs(dp[i]));

        }
        return max;
    }
    static boolean flag1=false;
    static boolean flag2=false;
    public void first(Runnable printFirst) throws InterruptedException {

        // printFirst.run() outputs "first". Do not change or remove this line.
        synchronized (this){
            flag1=true;
            printFirst.run();
            this.notifyAll();
        }

    }

    public void second(Runnable printSecond) throws InterruptedException {

        // printSecond.run() outputs "second". Do not change or remove this line.

        synchronized (this){
            while(!flag1){
                this.wait();
            }
            flag2=true;
            printSecond.run();
            this.notifyAll();

        }

    }

    public void third(Runnable printThird) throws InterruptedException {

        // printThird.run() outputs "third". Do not change or remove this line.
        synchronized (this){

            while(!flag2||!flag1){
                this.wait();
            }
            printThird.run();
        }
    }
    public static void main(String[] args) {
        Day10Test test=new Day10Test();
        new Thread(()->{
            try {
                test.first(() -> {
                    System.out.println("first");
                });
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"t1").start();
    }

}
